package com.swt.service.impl.S_impl;

import com.swt.dao.S_dao.GetInfoDao;
import com.swt.domain.Aboutcourse;
import com.swt.domain.Course;
import com.swt.service.S_service.GetInfoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service(value = "S_getInfoService")
@Transactional
public class GetInfoServiceImpl implements GetInfoService {
    /*注入dao*/
    @Resource(name = "S_getInfoDao")
    private GetInfoDao getInfoDao;

    @Override
    public List<Aboutcourse> getInfo(int clubid, int userid) {

        /*调用dao*/
        List<Aboutcourse> list = getInfoDao.getInfo(clubid, userid);
        return list;
    }

    @Override
    public void deleteInfo(int aboutcourseId) {
        /*根据id获取对应的预约信息*/
        Aboutcourse aboutcourse = getInfoDao.getInfoById(aboutcourseId);
        //根据预约信息取出课程id
        int courseid=aboutcourse.getAboutcourseCourseid();
        //根据课程id取出课程信息
        Course course = getInfoDao.getCourse(courseid);
        //修改数量
        course.setCourseRemainNum(course.getCourseRemainNum()+1);
        //保存到数据库
        getInfoDao.saveCourse(course);
        /*调用dao删除预约信息*/
        getInfoDao.deleteInfo(aboutcourse);
    }


}
